﻿using Xunit;

namespace Unity.String.Tests.Number
{
    public class FloatingPointInfoTest
    {
        [Fact]
        public void ConstructorAndPropertiesTest()
        {
            System.Number.FloatingPointInfo testDefaultFloatingPointInfo = 
                new System.Number.FloatingPointInfo();

            Assert.Equal(0, testDefaultFloatingPointInfo.DenormalMantissaBits);
            Assert.Equal(0ul, testDefaultFloatingPointInfo.DenormalMantissaMask);
            Assert.Equal(0, testDefaultFloatingPointInfo.ExponentBias);
            Assert.Equal(0u, testDefaultFloatingPointInfo.ExponentBits);
            Assert.Equal(0ul, testDefaultFloatingPointInfo.InfinityBits);
            Assert.Equal(0, testDefaultFloatingPointInfo.MaxBinaryExponent);
            Assert.Equal(0, testDefaultFloatingPointInfo.MinBinaryExponent);
            Assert.Equal(0, testDefaultFloatingPointInfo.NormalMantissaBits);
            Assert.Equal(0ul, testDefaultFloatingPointInfo.NormalMantissaMask);
            Assert.Equal(0, testDefaultFloatingPointInfo.OverflowDecimalExponent);
            Assert.Equal(0ul, testDefaultFloatingPointInfo.ZeroBits);
            
            ushort denormalMantissaBits = 23;
            ushort exponentBits = 8;
            int maxBinaryExponent = 127;
            int exponentBias = 127;
            ulong infinityBits = 0x7F800000;
            System.Number.FloatingPointInfo testSingleFloatingPointInfo = 
                new System.Number.FloatingPointInfo(
                    denormalMantissaBits, exponentBits,
                    maxBinaryExponent, exponentBias,
                    infinityBits);
            Assert.Equal(denormalMantissaBits, testSingleFloatingPointInfo.DenormalMantissaBits);
            ulong denormalMantissaMask = 0x007FFFFF;
            Assert.Equal(denormalMantissaMask, testSingleFloatingPointInfo.DenormalMantissaMask);
            Assert.Equal(exponentBias, testSingleFloatingPointInfo.ExponentBias);
            Assert.Equal(exponentBits, testSingleFloatingPointInfo.ExponentBits);
            
            Assert.Equal(infinityBits, testSingleFloatingPointInfo.InfinityBits);
            Assert.Equal(maxBinaryExponent, testSingleFloatingPointInfo.MaxBinaryExponent);
            int minBinaryExponent = -126;
            Assert.Equal(minBinaryExponent, testSingleFloatingPointInfo.MinBinaryExponent);

            ushort normalMantissaBits = 24;
            ulong normalMantissaMask = 0x00FFFFFF; 
            Assert.Equal(normalMantissaBits, testSingleFloatingPointInfo.NormalMantissaBits);
            Assert.Equal(normalMantissaMask, testSingleFloatingPointInfo.NormalMantissaMask);

            int overflowDecimalExponent = 58;
            Assert.Equal(overflowDecimalExponent, testSingleFloatingPointInfo.OverflowDecimalExponent);

            ulong zeroBits = 0;
            Assert.Equal(zeroBits, testSingleFloatingPointInfo.ZeroBits);
        }
        
    }
}